﻿Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports paycircuit.com.google.iap



'''<summary>
'''This is a test class for JSONHelpersTest and is intended
'''to contain all JSONHelpersTest Unit Tests
'''</summary>
<TestClass()> _
Public Class JSONHelpersTest

    Const MY_SELLER_ID As String = "YOUR_SELLER_ID"
    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''A test for dataContractJSONToObj
    '''</summary>
    <TestMethod()> _
    Public Sub dataContractJSONToObjTest()
        Dim jwtString As String = buildJsonString()
        jwtString = JWTHelpers.jwtEncodeB64Url(jwtString)
        Dim o As Object = New InAppItemObject()
        Dim actual As Object
        actual = JSONHelpers.dataContractJSONToObj(jwtString, o)
        Assert.IsTrue(actual IsNot Nothing)
        Assert.IsInstanceOfType(actual, GetType(InAppItemObject))
    End Sub

    '''<summary>
    '''A test for dataContractToJSON
    '''</summary>
    <TestMethod()> _
    Public Sub dataContractToJSONTest()
        Dim request As New InAppItemRequestObject() With
           {
               .name = "Burp",
               .description = "A digital representation of food for your palete",
               .price = "0.99",
               .currencyCode = RequestObject.SupportedCurrencies.USD.ToString()
           }
        Dim ClaimObj As New InAppItemObject(request) With {.iss = MY_SELLER_ID, .exp = .iat + 3600}

        Dim actual As String
        actual = JSONHelpers.dataContractToJSON(ClaimObj)

        Assert.Inconclusive("Expected fail - this test just writes out JSON: " + actual)
    End Sub

    Private Function buildJsonString() As String
        Dim request As New InAppItemRequestObject() With {.name = "foo"}
        Dim target As InAppItemObject = New InAppItemObject(request)

        target.iss = "this is required"
        ' target.response = New InAppItemResponseObject()
        Return JSONHelpers.dataContractToJSON(target)
    End Function

End Class
